package com.lzq.leetcode.hoot100;

public class s73 {

    public void setZeroes(int[][] matrix) {
        boolean flagRow = false;
        boolean flagCol = false;

        int l = matrix.length;
        int r = matrix[0].length;

        for (int i=0; i<l; i++) {
            if (matrix[i][0] == 0) {
                flagCol = true;
                break;
            }
        }

        for (int i=0; i<r; i++) {
            if (matrix[0][i] == 0) {
                flagRow = true;
                break;
            }
        }

        for (int i=1; i<l; i++) {
            for (int j=1; j<r; j++) {
                if (matrix[i][j] == 0) {
                    matrix[i][0] = 0;
                    matrix[0][j] = 0;
                }
            }
        }

        for (int i=1; i<l; i++) {
            for (int j=1; j<r; j++) {
                if (matrix[i][0] == 0 || matrix[0][j] == 0) {
                    matrix[i][j] = 0;
                }
            }
        }

        if (flagRow) {
            for (int i=0; i<r; i++) {
                matrix[0][i] = 0;
            }
        }

        if (flagCol) {
            for (int i=0; i<l; i++) {
                matrix[i][0] = 0;
            }
        }
    }
}
